package com.zb.controller;

import com.zb.entity.Student;
import com.zb.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by user on 2019/2/27.
 */
@Controller
@RequestMapping("/com/zb/cn")
public class StudentController {

    @Autowired
    private StudentService service;

    @RequestMapping("/listStudent")
    @ResponseBody
    public List<Student> listMytable(){
        return service.listMytable();
    }
    @RequestMapping("/toinfo")
    public String toinfo(@RequestParam(value = "id",required = false,defaultValue = "0") int id, Model model){
        Student student=service.showTwoTable(id);
        model.addAttribute("s",student);
        return "info.html";
    }

    @RequestMapping("/update")
    @ResponseBody
    public String update(String sname,@RequestParam(value = "cid",required = false) int cid,@RequestParam(value = "id",required = false) int id){
        int count=service.update(sname,cid,id);
        return Integer.toString(count);
    }

    @RequestMapping("/add")
    @ResponseBody
    public String add(String sname,@RequestParam(value = "cid",required = false)int cid){
        int count=service.add(sname,cid);
        return Integer.toString(count);
    }

    @RequestMapping("/del")
    @ResponseBody
    public String del(@RequestParam(value = "id",required = false)int id){
        int count=service.del(id);
        return Integer.toString(count);
    }
}
